GapK metric
Bases: SampledRewardMetric
pass@k minus pass^k; use to spot flaky programs, set batch_size=k.
A batched metric (each batch is one problem's k samples). The flakiness
between optimistic and consistent performance: 0 means a problem is
either always solved or never solved across the k samples; larger values
mean the agent's success is sample-dependent. Lower is more reliable
(direction = "down"). Averaged over the dataset.
Example:
import synalinks
class Question(synalinks.DataModel):
question: str
class Answer(synalinks.DataModel):
answer: str
K = 5
# Sampling (temperature > 0) so the K rollouts of one prompt differ.
inputs = synalinks.Input(data_model=Question)
outputs = await synalinks.Generator(
data_model=Answer,
language_model=synalinks.LanguageModel(model="openai/gpt-4o-mini"),
temperature=0.8,
)(inputs)
program = synalinks.Program(inputs=inputs, outputs=outputs)
# Report all three together: the optimistic bound, the consistency floor,
# and the gap between them.
program.compile(
reward=synalinks.rewards.ExactMatch(in_mask=["answer"]),
metrics=[
synalinks.metrics.PassAtK(k=K),
synalinks.metrics.PassHatK(k=K),
synalinks.metrics.GapK(k=K),
],
)
# repeat == batch_size == K -> each batch is one problem's K samples.
dataset = synalinks.HuggingFaceDataset(
hf_dataset_name="openai/gsm8k",
hf_config_name="main",
split="test",
input_data_model=Question,
output_data_model=Answer,
input_template='{"question": {{ question | tojson }}}',
output_template='{"answer": {{ answer.split("####")[-1].strip() | tojson }}}',
batch_size=K,
repeat=K,
limit=20,
)
metrics = await program.evaluate(x=dataset())
print(metrics["gap_k"]) # flakiness = pass@k - pass^k
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
The number of samples |
1
|
reward
|
Reward
|
Per-sample correctness signal (default |
None
|
pass_threshold
|
float
|
Reward threshold for a sample to count as
correct. Defaults to |
1.0
|
name
|
str
|
Optional. Name of the metric instance. |
'gap_k'
|
Source code in synalinks/src/metrics/agents_metrics.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | |